package com.itSiri.controller;

import com.itSiri.pojo.PageBean;
import com.itSiri.pojo.Result;
import com.itSiri.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@Slf4j
@RequestMapping("/emps")
@RestController
public class EmpController {
   @Autowired
    EmpService empService;
   @GetMapping
    public Result page(@RequestParam(defaultValue ="1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pagesize,
                       String name, Short gender,
                       @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-mm-dd")LocalDate end){
      log.info("分页查询,参数: {},{},{},{},{},{}",page,pagesize,name,gender,begin,end);
       PageBean pageBean = empService.page(page, pagesize, name, gender, begin, end);

       return Result.success(pageBean);
   }
   @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
       log.info("批量删除操作, ids:{}",ids);
       empService.delete(ids);
       return Result.success();
   }
}
